#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6 + 10;

ll read(){
    ll x = 0, t = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-') t = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }

    return x * t;
}

void print(ll x){
    if(x < 0){
        putchar('-');
        print(-x);
        return;
    }
    if(x > 9){
        print(x / 10);
    }
    putchar((x % 10) ^ 48);
}

ll T;
ll n, m, L, V;

ll d[N], v[N], a[N];
ll p[N];

ll ans1, ans2;

bool flag[N];

struct segm{
    ll l, r;
} seg[N];

int idx;

bool cmp(segm a, segm b){
    return (a.l == b.l ? (a.r < b.r) : (a.l < b.l));
}


void INIT(){
    n = read();
    m = read();
    L = read();
    V = read();

    for(int i = 1; i <= n; i++){
        d[i] = read();
        v[i] = read();
        a[i] = read();
    }

    for(int i = 1; i <= m; i++){
        p[i] = read();
    }
}

void ERASE(){
    n = m = L = V = 0;
    for(int i = 1; i <= n; i++){
        d[i] = a[i] = v[i] = 0;
    }
    for(int i = 1; i <= m; i++){
        p[i] = flag[i] = 0;
    }
    for(int i = 1; i <= idx; i++){
        seg[i] = {0, 0};
    }
    ans1 = ans2 = 0;
    idx = 0;
}

int bs1(int pos){
    int l = 1, r = m + 1;

    while(l < r){
        int mid = (l + r) >> 1;
        if(p[mid] < pos) l = mid + 1;
        else r = mid;
        //cout << l << endl;
    }
    return l;
}

bool check(int mid, int i){
    ll s = p[mid] - d[i];
    return 1ll * v[i] * v[i] + 2ll * a[i] * s <= V * V; 
}

int bs2(int i, int j){
    int l = j, r = m + 1;
    if(a[i] >= 0){
        while(l < r){
            int mid = (l + r) >> 1;
            if(check(mid, i)) l = mid + 1;
            else r = mid;
        }
    }
    else{
        // if(p[j] == d[i]) return j;
        // else if(j + 1 <= n && 1ll * v[i] * v[i] - 2ll * a[i] * (p[j + 1] - d[i]) > V * V){
        //     return j + 1;
        // }
        // else return n + 1;
        if(check(j, i)) return m + 1;

        while(l < r){
            int mid = l + r >> 1;
            if(check(mid, i)) r = mid;
            else l = mid + 1 ;
        }
        l--;
    }

    return l;
}




int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    T = read();
    
    while(T--){

        INIT();
        //cout << n << ' ' << m << ' ' << L << ' ' << V << endl;
       
        for(int i = 1; i <= n; i++){
            if(v[i] <= V && a[i] <= 0) continue;
            int pos = bs1(d[i]);
            if(pos == m + 1) continue;
            int x = bs2(i, pos);
           // cout << i << ' ' << pos << ' ' << x << endl;
            if(x == m + 1) continue;
            ans1++;
            if(a[i] >= 0){
                seg[++idx] = {x, m};
            }
            else{
                seg[++idx] = {pos, x};
            }
            //cout << i << ' ' << seg[idx].l << ' ' << seg[idx].r << endl;
        }

        sort(seg + 1, seg + idx + 1, cmp);
        int l = 1, r = 0;
        ll lst = 0, minn = 0x3f3f3f3f;
        for(int i = 1; i <= m; i++){
            while(r + 1 <= idx && seg[r + 1].l <= i){
                r++;
                minn = min(minn, seg[r].r);
            }
            if(minn == i){
                lst = i;
                l = r + 1;
                minn = 0x3f3f3f3f;
                ans2++;
                 //cout << p[i] << '\n';
            }
            else{
                if(i == m && l <= r && r <= idx){
                    ans2++;
                   // cout << p[i] << '\n';
                }
            }
            //while(l <= m && seg[l].r < i) l++;
            // if(seg[l].l > lst && (i + 1 > seg[l].r)){
            //     ans2++;
            //     //cout << p[i] << ' ';
            //     lst = i;
            // }
            //while(l <= m && seg[l].l <= lst) l++;
        }

        // for(int i = 1; i <= m; i++){
        //     if(flag[i]) {
        //         ans2++;
        //         cout << p[i] << ' ' ;
        //     }
        // }
        //cout << endl;
        print(ans1);
        putchar(' ');
        print(m - ans2);
        //cout << ' ' << m << ' ' << idx << ' ' << n;
        putchar('\n');

        ERASE();
    }


    return 0;
}